package 线程和TCP网络编程.TAKS2.失败品.Socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class SocketThread1 implements Runnable {

    public Socket socket;

    public SocketThread1(Socket socket) {
        //这里是使用初始化方法来将客户端的socket传入线程中
        //方便后续操作
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            /* Scanner sc = new Scanner(System.in);*/
            //这里是使用字符缓冲输入流来输入内容1
            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            while (true) {
                String str = br.readLine();
                pw.print(socket.getPort() + "say:" + str);
                pw.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}